package com.yiyun.blog.handler;

import com.yiyun.blog.vo.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 对加了@controller注解的方法进行拦截处理 AOP实现
 *
 * @author Bao
 * @create 2022-03-02-19:56
 */
@ControllerAdvice
public class AllExceptionHandler {

    //进行异常处理，处理Exception.class异常
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result doException(Exception ex){
        ex.printStackTrace();
        return Result.fail(-999,"系统异常");
    }
}
